namespace Vanilla.UI

import Vanilla

class ImageGadget (Gadget):
	public Bitmap as BitmapCanvas
	
	override MinSize as Size:
		get:
			return Size(100,100) if Bitmap == null
			return Bitmap.Size
	
	def constructor (p as Box, b as BitmapCanvas):
		super(p)
		Bitmap = b
	
	def constructor (p as Box, f as File):
		self(p, BitmapCanvas.Load(f))
	
	override def Draw (b as Brush):
		DrawContents(b)
	
	override def DrawContents (b as Brush):
		if Bitmap is null:
			print "-WARNING- ImageGadget's Bitmap is null!"
			return
	
		s = Bitmap.Size
	
		b.Translate(Size.Width / 2 - s.Width / 2, Size.Height / 2 - s.Height / 2)
		p = CanvasPattern(Bitmap)
		b.Pattern = p
		b.Draw(Rect(s))
		b.Fill()
